from functools import lru_cache
class Kapsnack(object):
     
    def __init__(self):
        self.weight = [0, 2, 2, 6, 5, 4, 100]
        self.values = [0, 6, 3, 5, 4, 6, 100]
        self.count = 0
 
    # @lru_cache(None)
    def comput(self, n=5, w=10):
        # 如果没有商品了返回0
        if n < 0:
            return 0
        self.count += 1
        # 如果不可以拿，就去拿下一个
        print("n=",n, )
        if self.weight[n] > w:
            return self.comput(n-1, w)
        else:

            # 如果可以拿，比较拿还是不拿的最大值
            result1 = self.comput(n-1, w-self.weight[n]) + self.values[n]
            result2 = self.comput(n-1, w)
            return max(result1, result2)
 
def test():
    pass

if __name__ == "__main__":
    n = 6
    w = 10
    k = Kapsnack()
    result = k.comput(n, w)
    print("count=", k.count)
    print('背包容量是{}的情况下，能偷到的最大的价值是{}'.format(w,result))
